home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / RCS / fsDisk.c,v < prev    next >
Encoding:
Text File  |  1989-06-08  |  19.8 KB  |  762 lines

  1. head     1.8;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    mendel:1.8; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.8
  10. date     89.01.06.08.14.38;  author brent;  state Exp;
  11. branches ;
  12. next     1.7;
  13.  
  14. 1.7
  15. date     87.05.27.14.34.45;  author brent;  state Exp;
  16. branches ;
  17. next     1.6;
  18.  
  19. 1.6
  20. date     87.05.19.12.14.44;  author brent;  state Exp;
  21. branches ;
  22. next     1.5;
  23.  
  24. 1.5
  25. date     87.05.11.11.18.18;  author brent;  state Exp;
  26. branches ;
  27. next     1.4;
  28.  
  29. 1.4
  30. date     87.05.08.17.45.18;  author brent;  state Exp;
  31. branches ;
  32. next     1.3;
  33.  
  34. 1.3
  35. date     86.07.24.11.35.31;  author brent;  state Exp;
  36. branches ;
  37. next     1.2;
  38.  
  39. 1.2
  40. date     86.07.21.09.36.00;  author brent;  state Exp;
  41. branches ;
  42. next     1.1;
  43.  
  44. 1.1
  45. date     86.07.18.09.32.40;  author brent;  state Exp;
  46. branches ;
  47. next     ;
  48.  
  49.  
  50. desc
  51. @Fs_AttachDisk et. al.
  52. @
  53.  
  54.  
  55. 1.8
  56. log
  57. @New include files and constants due to source reorganization
  58. @
  59. text
  60. @/* 
  61.  * fsDisk.c --
  62.  *
  63.  *    Routines related to managing local disks.
  64.  *
  65.  * Copyright 1986 Regents of the University of California
  66.  * All rights reserved.
  67.  */
  68.  
  69. #ifndef lint
  70. static char rcsid[] = "$Header: fsDisk.c,v 1.7 87/05/27 14:34:45 brent Exp $ SPRITE (Berkeley)";
  71. #endif not lint
  72.  
  73.  
  74. #include "sprite.h"
  75.  
  76. #include "fs.h"
  77. #include "fsDisk.h"
  78. #include "fsOpTable.h"
  79. #include "devDiskLabel.h"
  80. #include "dev.h"
  81. #include "devInt.h"
  82. #include "sync.h"
  83. #include "mem.h"
  84. #include "byte.h"
  85.  
  86. #include "boot.h"
  87.  
  88. /*
  89.  * Forward declarations.
  90.  */
  91. void FsGetFileDesc();
  92.  
  93. /*
  94.  * fsDevice is copied into all FsHandles.  It is used by the drivers to
  95.  * get to the partition and geometry information for the disk.
  96.  */
  97. Fs_Device fsDevice;
  98.  
  99. /*
  100.  * fsDomainPtr and fsRootHandlePtr are used by Fs_Open.
  101.  */
  102. static FsDomain fsDomain;
  103. FsDomain *fsDomainPtr = &fsDomain;
  104. static FsHandle fsRootHandle;
  105. FsHandle *fsRootHandlePtr = &fsRootHandle;
  106. static char fsLabelBuffer[DEV_BYTES_PER_SECTOR];
  107.  
  108. /*
  109.  *----------------------------------------------------------------------
  110.  *
  111.  * FsAttachDisk --
  112.  *
  113.  *    Set things up so we can call FsBlockIO to read the disk.
  114.  *    This makes sure the disk is up and reads the domain header.
  115.  *    The domain information is saved in a global area.
  116.  *
  117.  * Results:
  118.  *    SUCCESS if the disk was readable and had a good volume header.
  119.  *
  120.  * Side effects:
  121.  *    Sets up the FsDomainInfo for the domain.
  122.  *
  123.  *----------------------------------------------------------------------
  124.  */
  125. ReturnStatus
  126. Fs_AttachDisk(ctlrNum, unitNum, partNum)
  127.     int ctlrNum;    /* Controller number from boot command */
  128.     int unitNum;    /* Unit number from boot command */
  129.     int partNum;    /* Partition number from boot command */
  130. {
  131.     register ReturnStatus status;    /* Return code */
  132.     register int headerSector;        /* Starting sector of volume header */
  133.     register int numHeaderSectors;    /* Number of sectors in volume header */
  134.     register FsDomainHeader *headerPtr;    /* Domain information */
  135.     int sectorsRead;            /* Returned from read call */
  136.     /*
  137.      * Set up the global filesystem device, its type number is zero.
  138.      */
  139.     fsDevice.unit = unitNum;
  140. #ifdef SCSI_DISK_BOOT
  141.     fsDevice.type = FS_DEV_SCSI_DISK;
  142. #endif
  143. #ifdef XYLOGICS_BOOT
  144.     fsDevice.type = FS_DEV_XYLOGICS;
  145. #endif
  146.     /*
  147.      * Read the zero'th sector from the first partition to get the layout
  148.      * of the disk.  A read failure will fall into the No Disk Label error
  149.      * message.
  150.      */
  151.     sectorsRead = 1;
  152.     status = (*fsRawDeviceOpsTable[fsDevice.type].readWrite)(FS_READ,
  153.          fsDevice.unit / DEV_NUM_DISK_PARTS,    /* first partiton */
  154.          fsLabelBuffer, 0, §orsRead);
  155.     if (((Sun_DiskLabel *)fsLabelBuffer)->magic == SUN_DISK_MAGIC) {
  156.     /*
  157.      * For Sun formatted disks we put the volume header well past
  158.      * the disk label and the boot program.
  159.      */
  160.     headerSector = SUN_DOMAIN_SECTOR;
  161.     sectorsRead = FS_NUM_DOMAIN_SECTORS;
  162. #ifdef notdef
  163.     } else if (Fs_IsSpriteLabel(buffer)) {
  164.     headerSector = ((FsDiskHeader *)fsLabelBuffer)->domainSector;
  165.     sectorsRead = ((FsDiskHeader *)fsLabelBuffer)->numDomainSectors;
  166. #endif notdef
  167.     } else {
  168.     Sys_Printf("No label <%x>\n", status);
  169.     return(FAILURE);
  170.     }
  171.     /*
  172.      * Read and save the domain header.  Every
  173.      * partition should have a domain header.
  174.      */
  175.     headerPtr = (FsDomainHeader *)Mem_Alloc(DEV_BYTES_PER_SECTOR *
  176.                         sectorsRead);
  177.     status = (*fsRawDeviceOpsTable[fsDevice.type].readWrite)(FS_READ,
  178.          fsDevice.unit, (Address)headerPtr, headerSector,
  179.          §orsRead);
  180.     if (status != SUCCESS) {
  181.     return(status);
  182.     }
  183.  
  184.     fsDomainPtr->headerPtr = headerPtr;
  185.     if (headerPtr->magic != FS_DOMAIN_MAGIC) {
  186.     Sys_Printf("Bad magic <%x>\n", headerPtr->magic);
  187.     return(FAILURE);
  188.     }
  189.     /*
  190.      * Set up the device to reference the geometry information so we
  191.      * can do block IO.
  192.      */
  193.     fsDevice.data = (ClientData)&fsDomainPtr->headerPtr->geometry;
  194.     headerPtr->device = fsDevice;
  195.     
  196.     /*
  197.      * Set up a file handle for the root directory.  What is important
  198.      * is the device info (for Block IO) and the file descriptor itself.
  199.      */
  200.     FsInitFileHandle(fsDomainPtr, FS_ROOT_FILE_NUMBER, fsRootHandlePtr);
  201.     return(SUCCESS);
  202. }
  203.  
  204. /*
  205.  *----------------------------------------------------------------------
  206.  *
  207.  * Fs_BlocksToSectors --
  208.  *
  209.  *    Convert from block indexes (actually, fragment indexes) to
  210.  *    sectors using the geometry information on the disk.  This
  211.  *    is a utility for block device drivers.
  212.  *
  213.  * Results:
  214.  *    The sector number that corresponds to the fragment index.
  215.  *    The caller has to make sure that its I/O doesn't cross a
  216.  *    filesystem block boundary.
  217.  *
  218.  * Side effects:
  219.  *    None.
  220.  *
  221.  *----------------------------------------------------------------------
  222.  */
  223. #define SECTORS_PER_FRAG    (FS_FRAGMENT_SIZE / DEV_BYTES_PER_SECTOR)
  224. #ifdef SCSI_DISK_BOOT
  225. int
  226. Fs_BlocksToSectors(fragNumber, geoPtr)
  227.     register int fragNumber;
  228.     register FsGeometry *geoPtr;
  229. {
  230.     register int sectorNumber;    /* The sector corresponding to the fragment */
  231.     register int cylinder;    /* The cylinder number of the fragment */
  232.     register int rotationalSet;    /* The rotational set with cylinder of frag */
  233.     register int blockNumber;    /* The block number within rotational set */
  234.  
  235.     blockNumber        = fragNumber / FS_FRAGMENTS_PER_BLOCK;
  236.     cylinder        = blockNumber / geoPtr->blocksPerCylinder;
  237.     blockNumber        -= cylinder * geoPtr->blocksPerCylinder;
  238.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  239.     blockNumber        -= rotationalSet * geoPtr->blocksPerRotSet;
  240.  
  241.     sectorNumber = geoPtr->sectorsPerTrack * geoPtr->numHeads * cylinder +
  242.           geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  243.           rotationalSet +
  244.           geoPtr->blockOffset[blockNumber];
  245.     sectorNumber += (fragNumber % FS_FRAGMENTS_PER_BLOCK) * SECTORS_PER_FRAG;
  246.  
  247.     return(sectorNumber);
  248. }
  249. #endif SCSI_DISK_BOOT
  250.  
  251. /*
  252.  *----------------------------------------------------------------------
  253.  *
  254.  * Fs_BlocksToDiskAddr --
  255.  *
  256.  *    Convert from block indexes (actually, fragment indexes) to
  257.  *    disk address (head, cylinder, sector) using the geometry information
  258.  *     on the disk.  This is a utility for block device drivers.
  259.  *
  260.  * Results:
  261.  *    The disk address that corresponds to the disk address.
  262.  *    The caller has to make sure that its I/O doesn't cross a
  263.  *    filesystem block boundary.
  264.  *
  265.  * Side effects:
  266.  *    None.
  267.  *
  268.  *----------------------------------------------------------------------
  269.  */
  270. #ifdef XYLOGICS_BOOT
  271. void
  272. Fs_BlocksToDiskAddr(fragNumber, data, diskAddrPtr)
  273.     int fragNumber;    /* Fragment index to map into block index */
  274.     ClientData data;    /* ClientData from the device info */
  275.     register Dev_DiskAddr *diskAddrPtr;
  276. {
  277.     register FsGeometry *geoPtr;
  278.     register int sectorNumber;    /* The sector corresponding to the fragment */
  279.     register int cylinder;    /* The cylinder number of the fragment */
  280.     register int rotationalSet;    /* The rotational set with cylinder of frag */
  281.     register int blockNumber;    /* The block number within rotational set */
  282.  
  283.     geoPtr         = (FsGeometry *)data;
  284.     /*
  285.      * Map to block number because the rotational sets are laid out
  286.      * relative to blocks.  After that the cylinder is easy because we know
  287.      * blocksPerCylinder.  To get the head and sector we first get the
  288.      * rotational set (described in fsDisk.h) of the block and the
  289.      * block's sector offset (relative to the rotational set!).  This complex
  290.      * algorithm crops up because there isn't necessarily an even number
  291.      * of blocks per track.  The 'blockOffset' array in the geometry gives
  292.      * a sector index of each successive block in a rotational set. Finally,
  293.      * we can use the sectorsPerTrack to get the head and sector.
  294.      */
  295.     blockNumber        = fragNumber / FS_FRAGMENTS_PER_BLOCK;
  296.     cylinder        = blockNumber / geoPtr->blocksPerCylinder;
  297.     blockNumber        -= cylinder * geoPtr->blocksPerCylinder;
  298.     diskAddrPtr->cylinder = cylinder;
  299.  
  300.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  301.     blockNumber        -= rotationalSet * geoPtr->blocksPerRotSet;
  302.     sectorNumber    = geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  303.                 rotationalSet + geoPtr->blockOffset[blockNumber] +
  304.             (fragNumber % FS_FRAGMENTS_PER_BLOCK) * SECTORS_PER_FRAG;
  305.     diskAddrPtr->head    = sectorNumber / geoPtr->sectorsPerTrack;
  306.     diskAddrPtr->sector = sectorNumber -
  307.               diskAddrPtr->head * geoPtr->sectorsPerTrack;
  308. }
  309. #endif XYLOGICS_BOOT
  310.  
  311. /*
  312.  *----------------------------------------------------------------------
  313.  *
  314.  * Fs_SectorsToRawDiskAddr --
  315.  *
  316.  *      Convert from a sector offset to a raw disk address (cyl, head,
  317.  *      sector) using the geometry information on the disk.  This is a
  318.  *      utility for raw device drivers and does not pay attention to the
  319.  *      rotational position of filesystem disk blocks.
  320.  *
  321.  *    This should be moved to Dev
  322.  *
  323.  * Results:
  324.  *    The disk address that corresponds exactly to the byte offset.
  325.  *
  326.  * Side effects:
  327.  *    None.
  328.  *
  329.  *----------------------------------------------------------------------
  330.  */
  331. #ifdef XYLOGICS_BOOT
  332. int
  333. Fs_SectorsToRawDiskAddr(sector, numSectors, numHeads, diskAddrPtr)
  334.     register int sector;    /* Sector number, counting from zero  */
  335.     register int numSectors;    /* Number of sectors per track */
  336.     register int numHeads;    /* Number of heads on the disk */
  337.     register Dev_DiskAddr *diskAddrPtr;
  338. {
  339.     register int sectorsPerCyl;    /* The rotational set with cylinder of frag */
  340.  
  341.     sectorsPerCyl        = numSectors * numHeads;
  342.     diskAddrPtr->cylinder    = sector / sectorsPerCyl;
  343.     sector            -= diskAddrPtr->cylinder * sectorsPerCyl;
  344.     diskAddrPtr->head        = sector / numSectors;
  345.     diskAddrPtr->sector        = sector - numSectors * diskAddrPtr->head;
  346. }
  347. #endif XYLOGICS_BOOT
  348.  
  349. /*
  350.  *----------------------------------------------------------------------
  351.  *
  352.  * Fs_IsSunLabel --
  353.  *
  354.  *    Poke around in the input buffer and see if it looks like
  355.  *    a Sun format disk label.
  356.  *
  357.  * Results:
  358.  *    TRUE or FALSE
  359.  *
  360.  * Side effects:
  361.  *    None.
  362.  *
  363.  *----------------------------------------------------------------------
  364.  */
  365. #ifdef notdef
  366. Boolean
  367. Fs_IsSunLabel(buffer)
  368.     Address buffer;    /* Buffer containing zero'th sector */
  369. {
  370.     register Sun_DiskLabel *sunLabelPtr;
  371.  
  372.     sunLabelPtr = (Sun_DiskLabel *)buffer;
  373.     if (sunLabelPtr->magic == SUN_DISK_MAGIC) {
  374.     /*
  375.      * Should check checkSum...
  376.      */
  377.     return(TRUE);
  378.     } else {
  379.     Sys_Printf("Sun magic <%x>\n", sunLabelPtr->magic);
  380.     return(FALSE);
  381.     }
  382. }
  383. #endif
  384.  
  385. /*
  386.  *----------------------------------------------------------------------
  387.  *
  388.  * Fs_IsSpriteLabel --
  389.  *
  390.  *    Poke around in the input buffer and see if it looks like
  391.  *    a Sprite format disk header.
  392.  *
  393.  * Results:
  394.  *    TRUE or FALSE
  395.  *
  396.  * Side effects:
  397.  *    None.
  398.  *
  399.  *----------------------------------------------------------------------
  400.  */
  401. #ifdef notdef
  402. Boolean
  403. Fs_IsSpriteLabel(buffer)
  404.     Address buffer;    /* Buffer containing zero'th sector */
  405. {
  406.     register FsDiskHeader *diskHeaderPtr;
  407.  
  408.     diskHeaderPtr = (FsDiskHeader *)buffer;
  409.     if (diskHeaderPtr->magic == FS_DISK_MAGIC) {
  410.     return(TRUE);
  411.     } else {
  412. #ifndef NO_PRINTF
  413.     Sys_Printf("Sprite magic <%x>\n", diskHeaderPtr->magic);
  414. #endif
  415.     return(FALSE);
  416.     }
  417. }
  418. #endif
  419. @
  420.  
  421.  
  422. 1.7
  423. log
  424. @Wasn't calling the correct device type read routine.
  425. @
  426. text
  427. @d11 1
  428. a11 1
  429. static char rcsid[] = "$Header: fsDisk.c,v 1.6 87/05/19 12:14:44 brent Exp $ SPRITE (Berkeley)";
  430. a17 1
  431. #include "fsInt.h"
  432. a18 1
  433. #include "fsLocalDomain.h"
  434. d20 1
  435. a20 2
  436. #include "fsPrefix.h"
  437. #include "sunDiskLabel.h"
  438. @
  439.  
  440.  
  441. 1.6
  442. log
  443. @Added mapping routines for drivers that need head/sector/cylinder
  444. addresses.
  445. @
  446. text
  447. @d11 1
  448. a11 1
  449. static char rcsid[] = "$Header: fsDisk.c,v 1.5 87/05/11 11:18:18 brent Exp $ SPRITE (Berkeley)";
  450. d84 6
  451. d96 1
  452. a96 1
  453.     status = (*fsRawDeviceOpsTable[0].readWrite)(FS_READ,
  454. d112 1
  455. a112 1
  456.     Sys_Printf("No header <%x>\n", status);
  457. d121 1
  458. a121 1
  459.     status = (*fsRawDeviceOpsTable[0].readWrite)(FS_READ,
  460. @
  461.  
  462.  
  463. 1.5
  464. log
  465. @Final trimmed down version
  466. @
  467. text
  468. @d11 1
  469. a11 1
  470. static char rcsid[] = "$Header: fsDisk.c,v 1.4 87/05/08 17:45:18 brent Exp $ SPRITE (Berkeley)";
  471. d30 2
  472. d99 1
  473. a99 1
  474.     numHeaderSectors = FS_NUM_DOMAIN_SECTORS;
  475. d103 1
  476. a103 1
  477.     numHeaderSectors = ((FsDiskHeader *)fsLabelBuffer)->numDomainSectors;
  478. d106 1
  479. a106 1
  480.     Sys_Printf("No disk header <%x>\n", status);
  481. d114 1
  482. a114 1
  483.                         numHeaderSectors);
  484. d124 1
  485. a124 1
  486.     Sys_Printf("Bad disk magic <%x>\n", headerPtr->magic);
  487. d162 1
  488. d187 99
  489. @
  490.  
  491.  
  492. 1.4
  493. log
  494. @Updated to reflect changes in fs header files
  495. @
  496. text
  497. @d11 1
  498. a11 1
  499. static char rcsid[] = "$Header: fsDisk.c,v 1.3 86/07/24 11:35:31 brent Exp $ SPRITE (Berkeley)";
  500. a35 5
  501.  * Global variables used because there is only one domain during a boot.
  502.  */
  503. Address fsLabelBuffer;
  504.  
  505. /*
  506. d44 5
  507. a48 2
  508. FsDomain *fsDomainPtr;
  509. FsHandle *fsRootHandlePtr;
  510. a73 1
  511.     register  Address buffer;        /* Read buffer */
  512. a86 1
  513.     buffer = (Address)Mem_Alloc(DEV_BYTES_PER_SECTOR);
  514. d90 2
  515. a91 2
  516.          buffer, 0, §orsRead);
  517.     if (Fs_IsSunLabel(buffer)) {
  518. d98 1
  519. d100 3
  520. a102 2
  521.     headerSector = ((FsDiskHeader *)buffer)->domainSector;
  522.     numHeaderSectors = ((FsDiskHeader *)buffer)->numDomainSectors;
  523. a106 1
  524.     fsLabelBuffer = buffer;
  525. a119 1
  526.     fsDomainPtr = (FsDomain *)Mem_Alloc(sizeof(FsDomain));
  527. a135 1
  528.     fsRootHandlePtr = (FsHandle *)Mem_Alloc(sizeof(FsHandle));
  529. d201 1
  530. d219 1
  531. d237 1
  532. d254 1
  533. @
  534.  
  535.  
  536. 1.3
  537. log
  538. @more trimming
  539. @
  540. text
  541. @d11 1
  542. a11 1
  543. static char rcsid[] = "$Header: fsDisk.c,v 1.2 86/07/21 09:36:00 brent Exp $ SPRITE (Berkeley)";
  544. d90 1
  545. a90 1
  546.     buffer = (Address)Mem_Alloc(BYTES_PER_SECTOR);
  547. d114 1
  548. a114 1
  549.     headerPtr = (FsDomainHeader *)Mem_Alloc(BYTES_PER_SECTOR *
  550. d164 1
  551. a164 1
  552. #define SECTORS_PER_FRAG    (FS_FRAGMENT_SIZE / BYTES_PER_SECTOR)
  553. d168 1
  554. a168 1
  555.     register Fs_Geometry *geoPtr;
  556. @
  557.  
  558.  
  559. 1.2
  560. log
  561. @Scrunched the code down.  Solidified Fs_AttachDisk
  562. @
  563. text
  564. @d11 1
  565. a11 1
  566. static char rcsid[] = "$Header: fsDisk.c,v 1.1 86/07/18 09:32:40 brent Exp $ SPRITE (Berkeley)";
  567. d78 1
  568. a78 1
  569.     int numHeaderSectors;        /* Number of sectors in volume header */
  570. d118 1
  571. a118 1
  572.          &numHeaderSectors);
  573. d126 1
  574. a126 1
  575.     Sys_Printf("FsDiskAttach: Bad magic # <%x>\n", headerPtr->magic);
  576. d250 1
  577. d252 1
  578. @
  579.  
  580.  
  581. 1.1
  582. log
  583. @Initial revision
  584. @
  585. text
  586. @d11 1
  587. a11 1
  588. static char rcsid[] = "$Header: fsDisk.c,v 1.10 86/07/09 14:08:53 brent Exp $ SPRITE (Berkeley)";
  589. d25 1
  590. d33 1
  591. a33 2
  592. static Boolean IsSunLabel();
  593. static Boolean IsSpriteLabel();
  594. d35 4
  595. a38 1
  596. static Fs_Device fsDevice;
  597. d40 5
  598. a44 1
  599. FsDomain *fsDomainPtr;    /* Top level info for the boot domain */
  600. d46 5
  601. a50 1
  602. FsHandle *fsDiskHandlePtr;
  603. d57 3
  604. a59 7
  605.  *    Make a file handle for the raw disk we are booting from.
  606.  *    This makes sure the disk is up, reads the volume header,
  607.  *    and calls the initialization routine for the block I/O module
  608.  *    of the disk's driver.  By the time this is called the device
  609.  *    initialization routines have already been called from Dev_Config
  610.  *    so the device driver knows how the disk is partitioned into
  611.  *    volumes.
  612. d70 1
  613. a70 1
  614. Fs_AttachDisk(ctlrNum, unitNum, partNum, handlePtrPtr)
  615. a73 1
  616.     FsHandle **handlePtrPtr;    /* Return, handle for raw disk */
  617. d75 6
  618. a80 8
  619.     ReturnStatus status;    /* Error code */
  620.     Address buffer;        /* Read buffer */
  621.     int headerSector;        /* Starting sector of volume header */
  622.     int numHeaderSectors;    /* Number of sectors in volume header */
  623.     int sectorsRead;        /* Returned from read call */
  624.     FsHandle    *handlePtr;    /* Reference to file handle for root */
  625.     FsFileID    fileID;        /* ID for root directory of domain */
  626.  
  627. a84 1
  628.     buffer = (Address)Mem_Alloc(BYTES_PER_SECTOR);
  629. d86 3
  630. a88 7
  631.      * This dives right down to the device specific I/O routines in order
  632.      * to read the special info kept at the beginning of the volume.
  633.      * Once the volume header has been read the regular block I/O interface
  634.      * to the device can be used.
  635.      * Read the zero'th sector of the partition.  It has a copy of the
  636.      * disk header, and that describes how the rest of the zero'th
  637.      * cylinder is layed out.
  638. d90 1
  639. d93 3
  640. a95 8
  641.          fsDevice.unit, buffer, 0, §orsRead);
  642.     if (status != SUCCESS) {
  643.     return(status);
  644.     }
  645.     /*
  646.      * Check for different disk formats.
  647.      */
  648.     if (IsSunLabel(buffer)) {
  649. d102 3
  650. a104 5
  651.     } else if (IsSpriteLabel(buffer)) {
  652.     register FsDiskHeader *diskHeaderPtr;
  653.     diskHeaderPtr = (FsDiskHeader *)buffer;
  654.     headerSector = diskHeaderPtr->domainSector;
  655.     numHeaderSectors = diskHeaderPtr->numDomainSectors;
  656. d106 1
  657. a106 1
  658.     Sys_Printf("No disk header\n");
  659. d109 1
  660. d111 2
  661. a112 1
  662.      * Read the volume header and save it with the domain.
  663. d114 2
  664. a115 1
  665.     buffer = (Address)Mem_Alloc(BYTES_PER_SECTOR * numHeaderSectors);
  666. d117 2
  667. a118 1
  668.          fsDevice.unit, buffer, headerSector, &numHeaderSectors);
  669. d124 3
  670. a126 4
  671.     fsDomainPtr->headerPtr = (FsDomainHeader *)buffer;
  672.     if (fsDomainPtr->headerPtr->magic != FS_DOMAIN_MAGIC) {
  673.     Sys_Printf("FsDiskAttach: Bad magic # on volume header <%x>\n",
  674.                   fsDomainPtr->headerPtr->magic);
  675. d130 2
  676. a131 5
  677.      * Call the Block I/O initialization routine which sets up the
  678.      * ClientData part of *devicePtr to reference the Fs_Geometry
  679.      * part of the domain header.  Then overwrite the device
  680.      * specification at was on the disk because the device unit depends on
  681.      * the system configuration.
  682. d133 9
  683. a141 11
  684.     (*fsBlockOpsTable[0].init)(&fsDevice, &fsDomainPtr->headerPtr->geometry);
  685.     fsDomainPtr->headerPtr->device = fsDevice;
  686.  
  687.     fsDiskHandlePtr = (FsHandle *)Mem_Alloc(sizeof(FsHandle));
  688.     fsDiskHandlePtr->fileID.serverID = -1;
  689.     fsDiskHandlePtr->fileID.domain = 0;
  690.     fsDiskHandlePtr->fileID.fileNumber = 0;
  691.     fsDiskHandlePtr->fileID.version = -1;
  692.     fsDiskHandlePtr->domainToken = (ClientData)fsDomainPtr;
  693.  
  694.     *handlePtrPtr = fsDiskHandlePtr;
  695. d148 10
  696. a157 1
  697.  * IsSunLabel --
  698. d159 36
  699. d206 2
  700. a207 2
  701. static Boolean
  702. IsSunLabel(buffer)
  703. d219 1
  704. d227 1
  705. a227 1
  706.  * IsSpriteLabel --
  707. d240 2
  708. a241 2
  709. static Boolean
  710. IsSpriteLabel(buffer)
  711. a244 2
  712.     register int index;
  713.     register int checkSum;
  714. d250 1
  715. a252 45
  716. }
  717.  
  718. /*
  719.  *----------------------------------------------------------------------
  720.  *
  721.  * Fs_BlocksToSectors --
  722.  *
  723.  *    Convert from block indexes (actually, fragment indexes) to
  724.  *    sectors using the geometry information on the disk.  This
  725.  *    is a utility for block device drivers.
  726.  *
  727.  * Results:
  728.  *    The sector number that corresponds to the fragment index.
  729.  *    The caller has to make sure that its I/O doesn't cross a
  730.  *    filesystem block boundary.
  731.  *
  732.  * Side effects:
  733.  *    None.
  734.  *
  735.  *----------------------------------------------------------------------
  736.  */
  737. #define SECTORS_PER_FRAG    (FS_FRAGMENT_SIZE / BYTES_PER_SECTOR)
  738. int
  739. Fs_BlocksToSectors(fragNumber, geoPtr)
  740.     int fragNumber;
  741.     register Fs_Geometry *geoPtr;
  742. {
  743.     register int sectorNumber;    /* The sector corresponding to the fragment */
  744.     register int cylinder;    /* The cylinder number of the fragment */
  745.     register int rotationalSet;    /* The rotational set with cylinder of frag */
  746.     register int blockNumber;    /* The block number within rotational set */
  747.  
  748.     blockNumber        = fragNumber / FS_FRAGMENTS_PER_BLOCK;
  749.     cylinder        = blockNumber / geoPtr->blocksPerCylinder;
  750.     blockNumber        -= cylinder * geoPtr->blocksPerCylinder;
  751.     rotationalSet    = blockNumber / geoPtr->blocksPerRotSet;
  752.     blockNumber        -= rotationalSet * geoPtr->blocksPerRotSet;
  753.  
  754.     sectorNumber = geoPtr->sectorsPerTrack * geoPtr->numHeads * cylinder +
  755.           geoPtr->sectorsPerTrack * geoPtr->tracksPerRotSet *
  756.           rotationalSet +
  757.           geoPtr->blockOffset[blockNumber];
  758.     sectorNumber += (fragNumber % FS_FRAGMENTS_PER_BLOCK) * SECTORS_PER_FRAG;
  759.  
  760.     return(sectorNumber);
  761. @
  762.